package com.cosina.test;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

public class ColorCube extends Activity {

	@Override
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		DataManager.init(this.getResources());
		GLSurfaceView glView = new GLSurfaceView(this);
		Renderer render = new Lession19Render();
		
		if(render instanceof DirectionListener)
			directionListener = (DirectionListener)render;
		glView.setRenderer(render);
		setContentView(glView);
	}
	
	
	private DirectionListener directionListener;

	@Override
	public boolean onTrackballEvent(MotionEvent event) {
		if(event.getAction() == MotionEvent.ACTION_MOVE){
			if(null == directionListener)
				return true;
			float x = event.getX();
			float y = event.getY();
			if(event.getHistorySize()<= 0)
				return true;
			float xBefore = event.getHistoricalX(0);
			float yBefore = event.getHistoricalY(0);
			
			if(y-yBefore < 0){
				directionListener.doUp();
			}else if(y-yBefore > 0){
				directionListener.doDown();
			}
			if(x-xBefore < 0){
				directionListener.doLeft();
			}else if(x-xBefore > 0){
				directionListener.doRight();
			}
		}
		return super.onTrackballEvent(event);
	}
	
	
}